package com.homson.coreservice.serviceapp.transaction;

import com.homson.coreservice.serviceapi.action.TransactionActionApi;
import com.homson.coreservice.servicecommon.co.TransactionAddCO;
import com.homson.coreservice.servicecommon.expection.BizException;
import com.homson.coreservice.servicecommon.request.AddTransactionRequest;
import com.homson.coreservice.servicecommon.request.RequestParameter;
import com.homson.coreservice.servicecommon.response.BaseResponse;
import com.homson.servicedomain.domain.transaction.TransactionAddCommand;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/11/8 3:27 PM
 **/
@Service
@Slf4j
public class TransactionActionService implements TransactionActionApi {
    
    @Resource
    private TransactionAddCommand transactionAddCommand;
    @Override
    public BaseResponse addTransaction(RequestParameter<AddTransactionRequest> request) {
        TransactionAddCO transactionAddCO = request.getBody().getTransactionAddCO();
        try {
            transactionAddCommand.addTransaction(transactionAddCO);
            return BaseResponse.ok();
        } catch (BizException e) {
            log.error(TransactionActionService.class.getSimpleName(),e);
            return BaseResponse.fail(e.getMessage());
        }
    }
}
